package com.explore.demo.controller;


import com.explore.demo.common.ServerResponse;
import com.explore.demo.pojo.User;
import com.explore.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.Server;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaolainan
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/user")
@Api("用户有关的操作")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping
    @ApiOperation("获得全部的用户")
    public ServerResponse queryAll(HttpServletRequest request){
        return userService.queryAllUsers(request);
    }

    @PutMapping
    @ApiOperation("更改用户信息")
    public ServerResponse updateUser(@RequestBody User user, HttpServletRequest request){
        return userService.updateUser(user, request);
    }

    @GetMapping("/{account}")
    @ApiOperation("根据account查询用户信息")
    public ServerResponse getUserByAccount(@PathVariable("account") String account, HttpServletRequest request){
        return userService.queryUserByAccount(account, request);
    }

    @DeleteMapping
    @ApiOperation("根据account删除用户信息")
    public ServerResponse deleteUser(String account, HttpServletRequest request){
        return userService.deleteUser(account, request);
    }

    @PostMapping("/login")
    @ApiOperation("账号和密码验证登陆的接口")
    public ServerResponse login(@RequestParam("account") String account,
            @RequestParam("password") String password,
            HttpServletRequest request)
    {
        return userService.login(account, password, request);
    }

    @PostMapping("/login_verify")
    @ApiOperation("账号加验证码登陆的接口")
    public ServerResponse loginVerify(@RequestParam("account") String account,
            @RequestParam("verifyCode") String verifyCode,
            HttpServletRequest request){
        return userService.loginByVerifyCode(account, verifyCode, request);
    }

    @PostMapping("/register")
    @ApiOperation("用户注册")
    public ServerResponse userRegister(String account, String password, HttpServletRequest request){
        return userService.register(account,password, request);
    }

    @GetMapping("/logout")
    @ApiOperation("注销登录")
    public ServerResponse logout(HttpServletRequest request){
        return userService.logout(request);
    }

    @GetMapping("/verifyCode")
    @ApiOperation("根据手机号 获取验证码")
    public ServerResponse getVerifyCode(String account, HttpServletRequest request){
        return userService.generateVerifyCode(account, request);
    }

    @GetMapping("/star_list")
    @ApiOperation("查询自己收藏的职位")
    public ServerResponse getStarRecruitment(HttpServletRequest request){
        return userService.getStarRecruitment(request);
    }


    @GetMapping("/star")
    @ApiOperation("收藏职位")
    public ServerResponse setStarRecruitment(HttpServletRequest request, Integer recruitmentId){
        return userService.setStarRecruitment(request, recruitmentId);
    }

    @PostMapping("/change_head_portrait")
    @ApiOperation("更换自己的头像")
    @CrossOrigin
    public ServerResponse changeHeadPortrait(HttpServletRequest request, MultipartFile file){
        return userService.changeHeadPortrait(file, request);
    }

    @PostMapping("/create_resume")
    @ApiOperation("创建一个个人简历")
    public ServerResponse createResume(String awardInfo, String internship, String personSummary, HttpServletRequest request){
        return userService.createResume(awardInfo, internship, personSummary, request);
    }

    @PostMapping("/show_own_resume")
    @ApiOperation("查看自己的简历")
    public ServerResponse showResume(HttpServletRequest request){
        return userService.showOwnResume(request);
    }

    @PostMapping("/show_own_delivery_log")
    @ApiOperation("查看自己的投递记录")
    public ServerResponse showOwnDeliveryLog(HttpServletRequest request){
        return userService.showOwnDeliveryLog(request);
    }
}

